package org.tekmob.remindpal.controller;

import java.util.ArrayList;
import java.util.List;

import org.tekmob.remindpal.MyArrayAdapter;
import org.tekmob.remindpal.R;
import org.tekmob.remindpal.model.Info;
import org.tekmob.remindpal.model.Reminder;
import org.tekmob.remindpal.model.ReminderDAO;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.ListView;
import android.widget.TextView;
/**
 * This activity will be called when a reminder
 * in the ReminderList clicked
 * 
 * @author Annisa
 *
 */
@SuppressLint("NewApi")
public class DetailReminder extends Activity {

	public List<Reminder> reminder;
	public ReminderDAO dao;

	ListView listview;
	MyArrayAdapter infoArrayAdapter;
	ArrayList<Info> infoArray = new ArrayList<Info>();
	TextView title;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.list_view);

		title = (TextView)findViewById(R.id.ti);
		title.setText("Your Reminder Details");

		//Initiate database
		dao = new ReminderDAO(this);
		Intent i = getIntent();
		//final String name = i.getStringExtra("NAME");
		int id = i.getIntExtra("ID", 0);
		//reminder = dao.getAReminder(name);
		reminder = dao.getAReminder(id);

		String month = "";
		if (reminder.get(0).getMonth()==0) {
			month = "January";
		} else if (reminder.get(0).getMonth()==1) {
			month = "February";
		} else if (reminder.get(0).getMonth()==2) {
			month = "March";
		}else if (reminder.get(0).getMonth()==3) {
			month = "April";
		}else if (reminder.get(0).getMonth()==4) {
			month = "MAY";
		}else if (reminder.get(0).getMonth()==5) {
			month = "June";
		}else if (reminder.get(0).getMonth()==6) {
			month = "July";
		}else if (reminder.get(0).getMonth()==7) {
			month = "August";
		}else if (reminder.get(0).getMonth()==8) {
			month = "September";
		}else if (reminder.get(0).getMonth()==9) {
			month = "Octeber";
		}else if (reminder.get(0).getMonth()==10) {
			month = "November";
		}else if (reminder.get(0).getMonth()==11) {
			month = "December";
		}

		infoArray.add(new Info("Name", reminder.get(0).getName()));
		infoArray.add(new Info("Date", month +", "+reminder.get(0).getDate()+" "+reminder.get(0).getYear() ));
		infoArray.add(new Info("Time", ""+reminder.get(0).getHour()+":"+reminder.get(0).getMinute()));
		infoArray.add(new Info("Sound", reminder.get(0).getSound()));
		infoArray.add(new Info("Vibrate", ""+reminder.get(0).getVibrate()));
		infoArray.add(new Info("Increasing", ""+reminder.get(0).getIncreasing()));
		infoArray.add(new Info("Move", ""+reminder.get(0).getMove()));
		infoArray.add(new Info("Shake", ""+reminder.get(0).getShake()));

		//Setting to ListView
		infoArrayAdapter = new MyArrayAdapter(DetailReminder.this, R.layout.activity_list_detail_remindpal, infoArray);
		listview = (ListView) findViewById(R.id.list_view);
		listview.setItemsCanFocus(false);
		listview.setAdapter(infoArrayAdapter);


	}

	/*
	 * Initiate Option Menu
	 * @see android.app.Activity#onCreateOptionsMenu(android.view.Menu)
	 */
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.list_reminder, menu);
		return true;

	}

	/*
	 * Option Menu Handler
	 * @see android.app.Activity#onOptionsItemSelected(android.view.MenuItem)
	 */
	@Override
	public boolean onOptionsItemSelected(MenuItem item){
		switch(item.getItemId()) {
		case R.id.new_reminder:
			//click on create item
			Intent newReminder = new Intent(getApplicationContext(),NewReminder.class);
			startActivity(newReminder);
			break; 
		case R.id.show:
			//click on show item
			Intent showReminder = new Intent(getApplicationContext(),ShowReminder.class);
			startActivity(showReminder);
			break;
		case R.id.send:
			//click on send item
			Intent sendReminder = new Intent(getApplicationContext(),SendReminder.class);
			startActivity(sendReminder);
			break;
		}
		return true;	    
	}
}
